package com.heima.wemedia.service.controller;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dto.WmMaterialDto;
import com.heima.wemedia.service.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 自媒体素材表(WmMaterial)表控制层
 *
 * @author makejava
 * @since 2022-04-10 21:06:24
 */
@RestController
@RequestMapping("/api/vi/material")
@Api(value = "自媒体素材管理API",tags = "自媒体素材管理")
public class WmMaterialController {
    /**
     * 服务对象
     */
    @Resource
    private WmMaterialService wmMaterialService;

    /**
     * 素材上传
     */
    @PostMapping("upload_picture")
    @ApiOperation(value = "素材上传")
    public ResponseResult upload(MultipartFile multipartFile){
        return wmMaterialService.upload(multipartFile);
    }

    /**
     * 素材列表查询
     */
    @PostMapping("list")
    @ApiOperation(value = "素材列表查询")
    public ResponseResult list(@RequestBody WmMaterialDto dto){
        return wmMaterialService.queryByPage(dto);
    }

    /**
     * 素材删除
     */
    @DeleteMapping("del_picture/{id}")
    @ApiOperation(value = "素材删除")
    public ResponseResult delete(@PathVariable("id") Integer id){
        wmMaterialService.deleteById(id.longValue());
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 收藏素材
     *
     * @param id
     * @return
     */
    @PutMapping(path = "/collect/{id}")
    @ApiOperation(value = "素材收藏")
    public ResponseResult collect(@PathVariable("id") Long id) {
        return wmMaterialService.collect(id);
    }

    /**
     * 取消收藏素材
     *
     * @param id
     * @return
     */
    @PutMapping(path = "/cancel_collect/{id}")
    @ApiOperation(value = "素材取消删除")
    public ResponseResult cancel(@PathVariable("id") Long id) {
        return wmMaterialService.cancel(id);
    }

}

